import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [{
  path: '/',
  name: 'index',
  redirect: '/Login',
  component: () =>
    import( /* webpackChunkName: "about" */ '../views/Index.vue'),
  children: [
    {
      path: 'index',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Index.vue')
    },
    {
      path: 'home',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Home.vue')
    },
    {
      path: 'test',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/test.vue')
    },
    {
      path: 'Course',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Course.vue')
    },
    {
      path: 'history',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/History.vue')
    },
    {
      path: 'kown',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Kown.vue')
    },
    {
      path: 'End',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/End.vue')
    },
    {
      path: 'Analysis',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Analysis.vue')
    },
    {
      path: 'Year',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Year.vue')
    },
    {
      path: 'Random',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Random.vue')
    },
    {
      path: 'Analysis',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Analysis.vue')
    },
    {
      path: 'Model',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Model.vue')
    },
    {
      path: 'special',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Special.vue')
    },
    {
      path: 'practice',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Practice.vue')
    },
    {
      path: 'random',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Random.vue')
    },
    {
      path: 'Message',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Message.vue')
    },
    {
      path: 'Favorite',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/Favorite.vue')
    },
    {
      path: 'ceshi',
      component: () =>
        import( /* webpackChunkName: "about" */ '../views/pages/ceshi.vue')
    },
  ]
},
{
  path: '/Login',
  name: 'Login',
  // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited.
  component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
},
{
  path: '/Forget',
  name: 'Forget',
  component: () =>
    import( /* webpackChunkName: "about" */ '../views/Forget.vue')
},
{
  path: '/Change',
  name: 'Change',
  // route level code-splitting
  // this generates a separate chunk (about.[hash].js) for this route
  // which is lazy-loaded when the route is visited.
  component: () => import(/* webpackChunkName: "about" */ '../views/Change.vue')
},
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})



// 登录验证，导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// router.beforeEach((to, from, next) => {
//   if (to.path === '/index') {
//     next();
//   } else {
//     let token = localStorage.getItem('Authorization');
//     console.log(token);
//     if(token === null || token === ''){
//       // this.$message({
//       //   message: '请登录',
//       //   type: 'error'
//       // });
//       next('/login');
//       console.log('非登录入口' + token);
//     }else{
//       // next('/login');
//       console.log('登录入口' + token);
//       next();
//     }
//   }
// });



export default router
